package com.yqRecite.util.util;

import cn.hutool.core.io.FileUtil;//需要引入这个、引入不对、无法使用对应的方法
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;


/**
    上传图片、视频工具类
 */
public class ImgVideoUploadUtil {
//    @Autowired
//    GoodsFileInfoMapper gfMapper;

    private static final String ABSOLUTE_FILE_PATH = "D:\\32266\\upload\\images\\";

    /**
     * 文件上传 绝对
     * @param file
     * @return
     */
    public String upload(MultipartFile file, HttpServletRequest request) throws IOException {
        String originName = file.getOriginalFilename();
        // 1、文件名加个时间戳
        String fileName = FileUtil.mainName(originName) + System.currentTimeMillis() + "." + FileUtil.extName(originName);
        // 2、文件存放的绝对路径 存放名称
        String storageName = ABSOLUTE_FILE_PATH + fileName;
        // 3. 文件上传
        FileUtil.writeBytes(file.getBytes(),storageName );
        String final_fileName ="http://localhost:8282/images/" + fileName;
        return final_fileName;
    }
}

